/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.support.custom.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import reportcenter.support.custom.dominio.FilialDeparaqqtb;
import reportcenter.support.dbutil.ConnectionManager;
import reportcenter.support.resourceload.DataSourceConfig;
import reportcenter.support.resourceload.SqlProperties;

/**
 *
 * @author renan
 */
public class DeparaFilialQQTBDAO {
    
//    public List<FilialDeparaqqtb> findByQQCodfil(String qqCodfil){
//        List<FilialDeparaqqtb> listDepara = null;
//        
//        Connection conn = null;
//        try {
//            new ConnectionManager(new DataSourceConfig("db2prod"));
//            conn = ConnectionManager.ds.getConnection();
//            ConnectionManager.printDriverStats();
//            QueryRunner qRunner = new QueryRunner();
//            listDepara = (List<FilialDeparaqqtb>) qRunner.query(conn, "select * from cspadm.cc80f02 where codemp=1 and id_rede=1 and codfil in(" + qqCodfil + ")",
//                    new BeanListHandler(FilialDeparaqqtb.class));
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            DbUtils.closeQuietly(conn);
//        }
//        
//        return listDepara;
//    }
    
    public String findByQQCodfil(String qqCodfil){
        List<FilialDeparaqqtb> listDepara = null;
        
        Connection conn = null;
        try {
            new ConnectionManager(new DataSourceConfig("db2prod"));
            conn = ConnectionManager.ds.getConnection();
            ConnectionManager.printDriverStats();
            QueryRunner qRunner = new QueryRunner();
            listDepara = (List<FilialDeparaqqtb>) qRunner.query(conn, "select * from cspadm.cc80f02 where codemp=1 and id_rede=1 and codfil in(" + qqCodfil + ")",
                    new BeanListHandler(FilialDeparaqqtb.class));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DbUtils.closeQuietly(conn);
        }
        
        StringBuilder builder = new StringBuilder();
        int i=0;
        for(FilialDeparaqqtb f : listDepara){
            i++;
            builder.append(f.getNu_estab());
            if(listDepara.size() != i){
                builder.append(",");
            }
            
        }
        
        return builder.toString();
    }
    
    public Integer findByTBCodfil(Integer tbCodfil){
        Integer itgr = new Integer(0);
        
        return itgr;
    }
    
    public static void main(String[] args) {
        String str = new DeparaFilialQQTBDAO().findByQQCodfil("3,8,9");
        System.out.println("String -> " + str);
        
    }
}